<?php include "../public/header.php"?>
<?php include "../public/header_public.php"?>
<style>
    .dept_jigou{color: #FF9900;border: 1px solid #FF9900;padding: 2px 20px;border-radius: 5px;background-color: #ff99000d;cursor: pointer;}
    .dept_jigou:hover{color: #FFFFFF;background-color: #FF9900}
    .dept_bumen{color: #19BE6B;border: 1px solid #19BE6B;padding: 2px 20px;border-radius: 5px;background-color: #5fb8781c;cursor: pointer;}
    .dept_bumen:hover{color: #FFFFFF;background-color: #19BE6B}
    .minyuan_red{padding: 4px;background-color: red;border-radius: 50%;font-size: 0;margin-right: 6px;position: relative;top: -4px;}
    .minyuan_lv{padding: 4px;background-color: #19BE6B;border-radius: 50%;font-size: 0;margin-right: 6px;position: relative;top: -4px;}
    .layui-table tr td .laytp-tree-table-cell > .laytp-tree-table-cell-content{
        font-size: 13px;
    }
</style>
<body class="laytp-container">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title">选择收入科目（其他收入）</span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button class="layui-btn layui-btn-sm btn-dark marginr5" type="button" id="submit">确定</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">科目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>

<script type="text/javascript">
    // 单选多选分类 默认单选 choose_type传值为多选
    var choose_type = getQueryVariable('choose_type');
    if(choose_type === undefined || choose_type === false){
        choose_type = 'radio';
    }else{
        choose_type = 'checkbox';
    }

    var parent_dom = getQueryVariable('dom');
    var parent_domkey = getQueryVariable('domkey');
    var parent_page = getQueryVariable('page');

    var mytable, form;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable', 'treeTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable, treeTable=layui.treeTable;

        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        $("#cols_table").hide();
        $("#export_table").hide();
        mytable = treeTable.render({
            elem: "#datalist",
            id: "datalist",
            title: "收入科目",
            url: facade.url(ask_opt_get_engin_budshou_qi),
            where: {},
            page: false,
            height: 'full-140',
            soulSort: TabInit.soulSort,
            method: TabInit.method,
            toolbar: TabInit.toolbar,
            overflow: TabInit.overflow,
            defaultToolbar: TabInit.defaultToolbar,
            filter: TabInit.filter,
            request: TabInit.request,
            response: TabInit.response,
            contextmenu:get_table_contextmenu(soulTable)
            , tree: {
                iconIndex: 1        // 折叠图标显示在第几列
                , arrowType: 'arrow2'   // 自定义箭头风格
                , getIcon: function (d) {  // 自定义图标
                    // d是当前行的数据
                    if (d.children && d.children.length > 0) {  // 判断是否有子集
                        return '<i class="laytp-tree-icon laytp-tree-icon-folder"></i>';
                    } else {
                        return '<i class="laytp-tree-icon laytp-tree-icon-file"></i>';
                    }
                }
            }
            ,parseData: function (res) {
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data
                };
            }
            , cols: [[
                {type: "radio", fixed: 'left'}
                ,{field: 'name', title: '科目名称'}
            ]]
            , done: function (res) {
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();
                mytable.expandAll();


                chuli_hide_radio(res);
                form.render('checkbox');
            }
        });
        listTableSearch(form, table);


        $('#submit').on('click', function () {
            var checkStatus = mytable.checkStatus('datalist');
            var data = checkStatus;
            if(data.length < 1){
                facade.error("请选择数据");return false;
            }



            if(parent_page == '页面值'){

            }else{
                var str = '<button type="button" class="layui-btn layui-btn-sm btn-dark" key="'+data[0].id+'"><span class="choose_content">'+data[0].name+'' +
                    '</span><span class="choose_close" onclick="choose_close(this, \''+parent_dom+'\')">×</span></button>';
                $("#"+parent_dom , parent.document).html(str);
                parent.formValid(parent_dom);

            }

            layer_close();
        });
    });



    function chuli_hide_radio(data) {
        for(let key in data) {
            if(data[key].children && data[key].children.length > 0){
                $('tr[data-id=' + data[key]['id'] + '] .layui-form-radio').hide();
                $('tr[data-id=' + data[key]['id'] + '] input[type="radio"]').hide();
                chuli_hide_radio(data[key].children);
            }
        }
    }

    function searchTableFunc(form, table) {
        var data = form.val('TableSearchForm');
        mytable.reload('datalist', {
            where: data
        });
    }


    function listTableReset(){
        $("#TableSearchFormId")[0].reset();
        // $("#TableSearchFormId select option").removeAttr("selected");
        // render_from();
    }

</script>
</body>
</html>
